<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>

        //XHR对象
        const getJSON = function(url){
            const promise = new Promise(function(resolve,reject){
                //异步操作
                const handler = function(){
                    if(this.readyState !==4){
                        return;
                    }
                    if(this.status === 200){
                        resolve(this.response);
                    } else {
                        reject(new Error(this.statusText));
                    }
                }

                const client = new XMLHttpRequest();
                client.open("GET",url);
                client.onreadystatechange = handler;
                client.responseType = "json";
                client.setRequestHeader("Accept","application/json");
                client.send();
            })
            return promise;
        }

        getJSON('https://i.mooc.chaoxing.com/space/index').then((data) => {
            console.log(data)
        },(error) => {
            console.log(error)
        })

    </script>
</body>
</html>